package com.igeekhome.controller.api;

import com.igeekhome.dto.EmpDto;
import com.igeekhome.pojo.DNetwork;
import com.igeekhome.service.IStaffService;
import com.igeekhome.util.CommonUtil;
import com.igeekhome.util.ResultBean;
import com.igeekhome.util.TableResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @author Romeo
 */
@RestController
@RequestMapping("/api/staff")
public class StaffControllerApi {
    @Autowired
    private IStaffService staffService;
    
    
    /**
    * @Description 员工管理列表
    * @Param [session, page, limit]
    * @Return TableResultBean
    **/
    @RequestMapping("/staffManage")
    public TableResultBean powerManage(HttpSession session, Integer page, Integer limit) {
        DNetwork network = (DNetwork) session.getAttribute("network");
        TableResultBean tableResultBean = staffService.selectDetailedByNetworkId(network, page, limit);
        System.out.println("+++++++++++++++++++++++++++++++++++++++++++");
        System.out.println(tableResultBean);
        return tableResultBean;
    }
    
    
    /**
    * @Description 新增员工
    * @Param [session, empDto]
    * @Return com.igeekhome.util.ResultBean
    **/
    @RequestMapping("/addStaff")
    public ResultBean addStaff(HttpSession session, EmpDto empDto) {
        DNetwork network = (DNetwork) session.getAttribute("network");
        return staffService.backInsertId(network, empDto);
    }
    
    
    /**
    * @Description 编辑员工
    * @Param [empDto]
    * @Return com.igeekhome.util.ResultBean
    **/
    @RequestMapping("/editStaff")
    public ResultBean editStaff(EmpDto empDto) {
        System.out.println("_____________________");
        System.out.println(empDto);
        if("".equals(empDto.getLoginPassword())&&empDto.getLoginPassword()!=null){
            empDto.setLoginPassword(CommonUtil.md5(empDto.getLoginPassword()));
        }
        ResultBean resultBean = staffService.editStaff(empDto);
        return resultBean;
    }
    
    
    /**
    * @Description 删除员工
    * @Param [id]
    * @Return com.igeekhome.util.ResultBean
    **/
    @RequestMapping("/delStaff")
    public ResultBean delStaff(@RequestParam("staff_ids") Integer id) {
        return staffService.delStaff(id);
    }
    
    
}
